package com.shaoshaohuo.app.adapter;

import java.util.List;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.EcCategorySecond;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class ProductTypeSecondListAdapter<T> extends MyBaseAdapter<EcCategorySecond> {

	public ProductTypeSecondListAdapter(Context ctx, List<EcCategorySecond> list, boolean flag) {
		super(ctx, list, flag);
	}

	// @Override
	// public int getViewTypeCount() {
	// // TODO Auto-generated method stub
	// return 2;
	// }
	//
	@Override
	public int getItemViewType(int position) {
		if (list.get(position).isTitle) {
			return 1;
		} else {
			return 2;
		}
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup group) {

		EcCategorySecond item = list.get(pos);
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			// if (getItemViewType(pos) == 1) {
			// convertView =
			// LayoutInflater.from(context).inflate(R.layout.view_product_type_second_item_title,
			// null);
			// } else {
			convertView = View.inflate(context, R.layout.view_product_type_second_item, null);
			holder.titleText = ((TextView) convertView.findViewById(R.id.textview_title));
			holder.nameText = (TextView) convertView.findViewById(R.id.textview_name);
			// }

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		if (getItemViewType(pos) == 1) {
			holder.titleText.setVisibility(View.VISIBLE);
			holder.nameText.setVisibility(View.GONE);
			holder.titleText.setText(item.getTitle());
		} else {
			holder.titleText.setVisibility(View.GONE);
			holder.nameText.setVisibility(View.VISIBLE);
			holder.nameText.setText(item.getCatname());
		}

		return convertView;
	}

	static class ViewHolder {
		TextView nameText;

		TextView titleText;
	}

}
